package com.piece.mall.service;

import com.piece.core.framework.util.collection.MapUtil;
import com.piece.core.jpa.repository.BaseService;
import com.piece.mall.model.SmsSkuLadder;
import com.piece.mall.repository.SmsSkuLadderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import java.util.HashMap;

@Service
@Transactional
public class SmsSkuLadderService extends BaseService<SmsSkuLadder, String> {

    @Autowired
    private SmsSkuLadderRepository smsSkuLadderRepository;

    @PostConstruct
    public void initRepository() {
        setRepository(smsSkuLadderRepository);
    }

    /**
     * 根据sku主键查询商品阶梯价格
     */
    public SmsSkuLadder findOneBySkuId(Long skuId) {
        return smsSkuLadderRepository.findOneByCondition(MapUtil.builder(new HashMap<String, Object>())
                .put("skuId", skuId).build());
    }

    public void deleteBySkuId(Long skuId) {
        smsSkuLadderRepository.deleteByProperties("skuId", skuId);
    }
}
